<template>
  <el-dialog :title="title"
             :close-on-click-modal="false"
             width="800px"
             @close="$emit('close')" :visible.sync="visible">
    <el-form label-width="80px" :model="form" :rules="rules" ref="form">
      <el-form-item>
        <el-table :data="list"
                  v-loading="loading"
                  border
                  class="el-easy-ui-table">
          <el-table-column
            label="序号"
            type="index"
            width="50">
          </el-table-column>
          <el-table-column
            prop="content"
            label="备注"
            min-width="250">
          </el-table-column>
          <el-table-column
            prop="createUser"
            label="备注人"
            width="120">
          </el-table-column>
          <el-table-column
            label="备注时间"
            width="160">
            <template slot-scope="scope">
              <div>{{scope.row.createTime | datetimeFormat}}</div>
            </template>
          </el-table-column>
        </el-table>
      </el-form-item>
      <el-form-item label="备注" prop="content">
        <el-input v-model="form.content" type="textarea" :autosize="{ minRows: 2, maxRows: 8}"></el-input>
      </el-form-item>
    </el-form>
    <div class="center-box">
      <el-button @click="visible = false">取 消</el-button>
      <easy-button type="primary" @click="onOk">保存备注</easy-button>
    </div>
  </el-dialog>
</template>

<script>

export default {
  name: 'RemarkDialog',
  props: {
    data: {
      type: Object,
      default () {
        return {
          localOrderId: ''
        }
      }
    }
  },
  data () {
    return {
      title: '新增备注',
      loading: false,
      visible: true,
      list: [],
      form: {
        localOrderId: this.data.localOrderId,
        content: ''
      },
      rules: {
        content: this.$checkRules.orderRemark.content
      }
    }
  },
  created () {
    this.loadRemarkList()
  },
  methods: {
    onOk (done) {
      this.$refs['form'].validate((valid) => {
        // 校验通过
        if (valid) {
          this.$service.order.saveOrderRemark(this.form).then(() => {
            this.$emit('ok')
            this.loadRemarkList()
          }).finally(() => {
            done()
          })
        } else {
          done()
        }
      })
    },
    loadRemarkList () {
      this.loading = true
      this.$service.order.queryOrderRemarkList({localOrderId: this.data.localOrderId}).then(res => {
        this.list = res.data
      }).finally(() => {
        this.loading = false
      })
    }
  }
}
</script>

<style></style>
